clc
clear

global input predicted

% Dave DeSteno's neutral, gratitude, happiness manipulations
% using kirby et al 1999 27 choices
% sooner	SS	later	LL
% dates in months
stimuli = [0	54	3.846575342	55
0	55	2.005479452	75
0	19	1.742465753	25
0	31	0.230136986	85
0	14	0.624657534	25
0	47	5.260273973	50
0	15	0.42739726	35
0	25	0.460273973	60
0	78	5.326027397	80
0	40	2.038356164	55
0	11	0.230136986	30
0	67	3.912328767	75
0	34	6.115068493	35
0	27	0.690410959	50
0	69	2.991780822	85
0	49	2.926027397	60
0	80	5.161643836	85
0	24	0.953424658	35
0	33	0.460273973	80
0	28	5.884931507	30
0	34	0.98630137	50
0	25	2.630136986	30
0	41	0.657534247	75
0	54	3.649315068	60
0	54	0.98630137	80
0	22	4.471232877	25
0	20	0.230136986	55];
% choseLL (appended to stimuli above)
for z=1:1
%     data = [0
% 0.565217
% 0.173913
% 1
% 0.869565
% 0
% 1
% 1
% 0
% 0.217391
% 1
% 0.086957
% 0
% 0.869565
% 0.347826
% 0.173913
% 0
% 0.391304
% 1
% 0
% 0.695652
% 0
% 0.826087
% 0
% 0.826087
% 0
% 1
% 0.043478
% 0.782609
% 0.434783
% 1
% 0.956522
% 0.086957
% 1
% 1
% 0.086957
% 0.565217
% 1
% 0.217391
% 0
% 1
% 0.391304
% 0.304348
% 0.086957
% 0.521739
% 1
% 0.043478
% 0.913043
% 0.130435
% 1
% 0.086957
% 1
% 0.086957
% 1
% 0.052632
% 0.789474
% 0.368421
% 1
% 0.894737
% 0
% 1
% 1
% 0
% 0.263158
% 1
% 0.052632
% 0
% 0.947368
% 0.368421
% 0.210526
% 0.052632
% 0.368421
% 1
% 0
% 0.684211
% 0.105263
% 0.947368
% 0
% 0.842105
% 0
% 1];
data = [0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
0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
1
0
0
1
1
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
1
1
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
0
0
0
0
1
0
1
0
0
0
1
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
1
1
0
1
1
0
0
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
0
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
1
0
1
0
1
0
1
1
1
0
1
0
0
0
1
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
0
1
0
1
0
0
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
1
0
1
1
0
1
0
1
0
1
0
1
0
0
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
1
1
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
1
0
1
0
1
1
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
1
0
0
1
1
1
0
1
1
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
1
1
0
0
1
0
0
1
0
0
0
1
1
0
1
0
1
0
1
0
1];
end
T = size(stimuli,1);
N = size(data,1)/T;

options = optimset('fmincon');
options.TolFun = 1e-10;
% options.MaxFunEvals = 1000;
% options.MaxIter = 1000;
% % Add to end of function calls ,[],options

expresults = zeros(N,6);
exppredicts = zeros(N*T,1);
for i = 1:N
    input = [stimuli data((i-1)*T+1:i*T,:)];
    [x,fval,exitflag,output,lamda,grad,hessian] = fmincon(@expdiscountMLE,[.1,.4],[],[],[],[],[0,0],[1,10000],[],options);
    stderr = ((diag(hessian)).^-.5)';
    exppredicts((i-1)*T+1:i*T,1) = predicted;
    expresults(i,:) = [x,stderr,fval,exitflag];
    % delta (discount factor), precision, SE(d), SE(p), fval, exitflag
end

hypresults = zeros(N,6);
hyppredicts = zeros(N*T,1);
for i = 1:N
    input = [stimuli data((i-1)*T+1:i*T,:)];
    [x,fval,exitflag,output,lamda,grad,hessian] = fmincon(@hypdiscountMLE,[.5,.4],[],[],[],[],[0,0],[100,10000],[],options);
    stderr = ((diag(hessian)).^-.5)';
    hyppredicts((i-1)*T+1:i*T,1) = predicted;
    hypresults(i,:) = [x,stderr,fval,exitflag];
    % kappa, precision, SE(k), SE(p), fval, exitflag
end

% delta (discount factor), precision, SE(d), SE(p), fval, exitflag, kappa, precision, SE(k), SE(p), fval, exitflag
results = [expresults hypresults];
predicts = [exppredicts hyppredicts];